<template>
  <div class="wrapper">
    <!--v-if 确保轮播图默认显示第一张-->
    <swiper :options="swiperOption" v-if="showSwiper">
      <!-- slides -->
      <swiper-slide v-for="item of list" :key="item.id">
        <img class="swiper-img" :src="item.imgUrl" :alt="item.alt">
      </swiper-slide>
      <!-- Optional controls -->
      <div class="swiper-pagination"  slot="pagination"></div>
      <!--轮播左右箭头，滚动条-->
      <!--<div class="swiper-button-prev" slot="button-prev"></div>
      <div class="swiper-button-next" slot="button-next"></div>
      <div class="swiper-scrollbar"   slot="scrollbar"></div>-->
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeSwiper',
  props: {
    list: Array
  },
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination',
        // 循环轮播
        loop: true,
        passiveListeners: false
      }
    }
  },
  computed: {
    showSwiper: function () {
      return this.list.length
    }
  }
}
</script>

<style scoped lang="stylus">
  // 设置分页点的颜色，因为它这个样式是外部组件的，所以用>>>表示样式穿透，不受限制
  .wrapper >>> .swiper-pagination-bullet-active
    background #ffffff
  //wrapper用来去除图片抖动
  .wrapper
    width 100%
    height 0
    overflow hidden
    padding-bottom 31%
    //或者用，不过可能浏览器不兼容
    //height 31.25%
    background #eaeaea
    .swiper-img
      width 100%
</style>
